package com.mdc.mansion.web.modules.dishes.web;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.mdc.mansion.web.modules.system.utils.UserUtils;
import com.mdc.mansion.dataaccess.modules.system.entity.User;

import com.mdc.mansion.dataaccess.common.persistence.Page;
import com.mdc.mansion.dataaccess.modules.dishes.entity.RestaurantDishesComboItem;
import com.mdc.mansion.core.modules.dishes.RestaurantDishesComboItemService;
import com.mdc.mansion.web.common.web.BaseController;
/**
 * 餐厅菜品套餐明细信息Controller
 * @author mingdongc
 * @version 2018-01-01
 */
@Controller
@RequestMapping(value = "${adminPath}/dishes/restaurantDishesComboItem")
public class RestaurantDishesComboItemController extends BaseController {

	@Autowired
	private RestaurantDishesComboItemService restaurantDishesComboItemService;
	
	@ModelAttribute
	public RestaurantDishesComboItem get(@RequestParam(required=false) String id) {
		if (StringUtils.isNotBlank(id)){
			return restaurantDishesComboItemService.get(id);
		}else{
			return new RestaurantDishesComboItem();
		}
	}
	
	@RequiresPermissions("dishes:restaurantDishesComboItem:view")
	@RequestMapping(value = {"list", ""})
	public ModelAndView list(RestaurantDishesComboItem restaurantDishesComboItem) {
		Map<String, Object> model=new HashMap<String, Object>();
		Page<RestaurantDishesComboItem> page = restaurantDishesComboItemService.findPage(restaurantDishesComboItem);
        model.put("page", page);
		ModelAndView modelAndView=new ModelAndView("modules/dishes/restaurantDishesComboItemList", model);
		return modelAndView;
	}
	
	@RequiresPermissions("dishes:restaurantDishesComboItem:view")
	@RequestMapping(value = "form")
	public ModelAndView form(RestaurantDishesComboItem restaurantDishesComboItem) {
		Map<String, Object> model=new HashMap<String, Object>();
		model.put("restaurantDishesComboItem", restaurantDishesComboItem);
		return new ModelAndView("modules/dishes/restaurantDishesComboItemForm",model);
	}
	

	@RequiresPermissions("dishes:restaurantDishesComboItem:edit")
	@RequestMapping(value = "save")
	public ModelAndView save(RestaurantDishesComboItem restaurantDishesComboItem,RedirectAttributes redirectAttributes) {
		User u=UserUtils.getUser();
		restaurantDishesComboItem.setUpdateBy(u);
		if (StringUtils.isNotBlank(restaurantDishesComboItem.getId())){
			restaurantDishesComboItemService.updateSelective(restaurantDishesComboItem);
		}else{
			restaurantDishesComboItem.setCreateBy(u);
			restaurantDishesComboItemService.save(restaurantDishesComboItem);
		}
		this.addMessage(redirectAttributes, "操作成功");
		return new ModelAndView("redirect:./list");
	}
	
	@RequiresPermissions("dishes:restaurantDishesComboItem:edit")
	@RequestMapping(value = "delete")
	public ModelAndView delete(RestaurantDishesComboItem restaurantDishesComboItem,RedirectAttributes redirectAttributes) {
		restaurantDishesComboItemService.delete(restaurantDishesComboItem);
		this.addMessage(redirectAttributes, "操作成功");
		return new ModelAndView("redirect:./list");
	}
	
}
